﻿define([],
    function () {

        var activateThemeConfig = function () {
            var script = document.createElement("script");
            script.type = "text/javascript";
            script.src = "../../Content/theme/js/config.js";
            document.body.appendChild(script);
        };

        var runCarousel = function () {
            $("#banner").oneByOne({													// the wrapper's name	
                className: 'oneByOne1',	             								// the wrapper div's class name of each slider	
                /* Please provide the width and height in the responsive 
                version, for the slider will keep the ratio when resize 
                depends on these size. */
                pauseByHover: true,													// pause the auto delay slideshow when user hover		
                width: 940,															// width of the slider		
                height: 341,														// height of the slider		
                easeType: 'random',													// will override effect if you don't pre-defined it in the element
                delay: 300,  														// the delay of the touch/drag tween	
                tolerance: 0.25, 													// the tolerance of the touch/drag
                slideShow: true,													// auto play the slider or not		
                slideShowDelay: 3000,												// the delay millisecond of the slidershow	
                responsive: true,													// slider's size with the media query in CSS
                minWidth: 480														// text is hidden at this width
            });
        };

        var detectIDevice = function () {
            /* ---------------------------------------------------------------------- */
            /*	Function Detect iDevice
             *	Documentation: http://ivaynberg.github.com/select2/	
            /* ---------------------------------------------------------------------- */
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {

                /* ---------------------------------------------------------------------- */
                /*	Initialize Hide iDevice Address bar
                /* ---------------------------------------------------------------------- */

                window.addEventListener("load", function () {

                    // Set a timeout...

                    setTimeout(function () {

                        // Hide the address bar!

                        window.scrollTo(0, 1);
                    }, 0);
                });

                /*end hide address*/

                // Initialize Append Phone Footer

                createPhoneFooter();

            } else {

                //Initialize Select2 if iDevice = false
                $(".chzn-select").select2();
            }
        };

        var bindToEventList = function(rootSelector, selector, callBack, eventName) {
            $(rootSelector).on(eventName, selector, function() {
                var entityObservable = ko.dataFor(this);
                callBack(entityObservable);
                return false;
            });
        };

        var displayGallery = function () {
            var gallery = new $.ThumbnailGallery($(".gallery"));
        };

        var helpers = {
            activateThemeConfig: activateThemeConfig,
            detectIDevice: detectIDevice,
            runCarousel: runCarousel,
            bindToEventList: bindToEventList,
            displayGallery: displayGallery
        };

        return helpers;

    });